import { MES_LXK_ApiHost } from '@/utils/Interceptors'

// 定义数据类型
export interface OutputStatistics {
  statisticsId: number
  reportingDate: string
  workOrderId: number
  workOrderNumber: string
  workOrderPlanQuantity: number
  productId: number
  productNumber: string
  productName: string
  productSpecification: string
  productQuantity: number
  unit: string
  isDelete: boolean
}

export interface ApiResponse {
  code: number
  msg: string
  data: OutputStatistics[]
}

export interface SearchParams {
  startTime?: string
  endTime?: string
  workOrderNumber?: string
  productName?: string
  productNumber?: string
}

// 获取所有产量统计数据
export const getAllOutputStatistics = async (params?: SearchParams) => {
  return await MES_LXK_ApiHost.get<ApiResponse>('/api/OutputStatistics/GetAllOutputStatistics', { params })
}

// 根据条件搜索产量统计数据
export const searchOutputStatistics = async (params: SearchParams) => {
  return await MES_LXK_ApiHost.get<ApiResponse>('/api/OutputStatistics/GetAllOutputStatistics', { params })
}

// 导出产量统计数据
export const exportOutputStatistics = async (params?: SearchParams) => {
  return await MES_LXK_ApiHost.get('/api/OutputStatistics/ExportOutputStatistics', { 
    params,
    responseType: 'blob',
    headers: {
      'Accept': 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel, */*'
    }
  })
}
